<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
class Captcha extends ParentCaptcha {
	function Captcha($code) {
		$this->get_fonts();
		
		$font = $this->font;

		$count=5;
		$width = $this->width;
		$height = $this->height;
		$font_size_min=32;
		$font_size_max=32;
		$font_file=$font;
		$char_angle_min=-10;
		$char_angle_max=10;
		$char_angle_shadow=5;
		$char_align=40;
		$start=5;

		$image=imagecreatetruecolor($width, $height);

		$background_color=imagecolorallocate($image, mt_rand(200,255), mt_rand(200,255), mt_rand(200,255)); 
		$font_color=imagecolorallocate($image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 

		imagefill($image, 0, 0, $background_color);

		$str="";

		$nmc = strlen($code);
		$start = 7;
			for ($i=0; $i<$nmc; $i++) {
			$char=$code[$i];
			$font_size=rand($font_size_min, $font_size_max);
			$char_angle=rand($char_angle_min, $char_angle_max);
			$bbox = imagettfbbox($font_size,$char_angle,$font_file,$char);
			imagettftext($image, $font_size, $char_angle, $start, $char_align, $font_color, $font_file, $char);
			imagettftext($image, $font_size, $char_angle+$char_angle_shadow*(rand(0, 1)*2-1), $start, $char_align, $background_color, $font_file, $char);
			$start+=$bbox['0'] + $bbox['2'];
			$str.=$char;
		}

		$image = $this->wave($image);

		$this->out_img($image);

		imagedestroy($image);


	}
}